#ifndef EVENT_H
#define EVENT_H
#include"object.h"
#include"slotlistener.h"
#include"Json/value.h"
#include<iostream>
#include<functional>

#define SEL_EVENTFUNC(func) static_cast<SEL_EventFunc>(&func)

typedef void (Object::*SEL_EventFunc)(Json::Value&);

typedef struct _Event{
    Object* handler;
    SEL_EventFunc func;
}EventHandler;

 class Slot
 {
 public:
     Slot(SlotListener* listener, const EventHandler& evh, const bool& once = false);

     Slot(SlotListener* listener,const std::function<void(Json::Value&)>& func, const bool& once = false);

     virtual ~Slot() {}

     virtual void dispatch(Json::Value& message);

     bool operator==(const Slot& slot);

     long long int getId() const;

     void remove();
 private:
     long long int id;
     bool flag = 0;
     EventHandler evh;
     std::function<void(Json::Value&)> func;
     bool once;
     SlotListener* listener;

     static long long int count;
 };

 EventHandler handler(Object* obj, SEL_EventFunc func);

#endif // EVENT_H
